package dcedit.factories;

// Import Java SDK Classes
import javax.swing.*;
import java.awt.event.*;
import java.io.File;

// Import Apache Commons Classes
import org.apache.commons.io.FilenameUtils;

// Import Application Classes
import dcedit.DCEdit;
import dcedit.util.Constants;
import dcedit.util.Util;

/** MenuFactory class */
public class MenuFactory {
   /** Private Constructor */
   private MenuFactory() {} // constructor

   /**
    * createAppMenuBar method<br/>
    * Delegates menu creation to other methods in the class.<br/>
    * @param APP Reference to the DCEdit frame class.<br/>
    * @return JMenuBar The menu bar.<br/>
    * @see #createFileMenu(DCEdit)
    * @see #createEditMenu()
    * @see #createLookAndFeelMenu(DCEdit)
    * @see #createHtmlMenu()
    * @see #createJavaMenu()
    * @see #createJavaFXMenu()
    * @see #createSqlMenu()
    * @see #createPythonMenu()
    * @see #createCustomMenu()
    * @see Util#haveDCEditCustomTemplates()
    */
   public static JMenuBar createAppMenuBar(final DCEdit APP) {
      final JMenuBar MENU_BAR = new JMenuBar();

      MENU_BAR.add(createFileMenu(APP));
      MENU_BAR.add(createEditMenu());
      MENU_BAR.add(createLookAndFeelMenu(APP));
      MENU_BAR.add(createHtmlMenu());
      MENU_BAR.add(createJavaMenu());
      MENU_BAR.add(createJavaFXMenu());
      MENU_BAR.add(createSqlMenu());
      MENU_BAR.add(createPythonMenu());
      if(Util.haveDCEditCustomTemplates()) {
         MENU_BAR.add(createCustomMenu());
      } // END if

      return MENU_BAR;
   } // END createAppMenuBar

   /**
    * createFileMenu method<br/>
    * @param APP Reference to the DCEdit frame class.<br/>
    * @return JMenu The menu.<br/>
    * @see ActionFactory#createNewTabActionListener()
    * @see ActionFactory#createOpenTabActionListener()
    * @see ActionFactory#createSaveActionListener()
    * @see ActionFactory#createSaveAsActionListener()
    * @see ActionFactory#createSaveAsTemplateActionListener()
    * @see ActionFactory#createTranslateTemplateActionListener()
    * @see ActionFactory#createCloseActionListener()
    * @see ActionFactory#createCloseAllActionListener()
    * @see ActionFactory#createCloseOthersActionListener()
    * @see ActionFactory#createExitActionListener()
    */
   public static JMenu createFileMenu(final DCEdit APP) {
      final JMenu MENU = new JMenu(Constants.FILE_TEXT);

      MENU.add(createMenuItem(Constants.NEW_TEXT,
                              ActionFactory.createNewTabActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.OPEN_TEXT,
                              ActionFactory.createOpenTabActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.SAVE_TEXT,
                              ActionFactory.createSaveActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.SAVE_AS_TEXT,
                              ActionFactory.createSaveAsActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.SAVE_AS_TEMPLATE_TEXT,
                              ActionFactory.createSaveAsTemplateActionListener()));
      MENU.add(createMenuItem(Constants.TRANSLATE_TEMPLATE_TEXT,
                              ActionFactory.createTranslateTemplateActionListener()));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.CLOSE_TEXT,
                              ActionFactory.createCloseActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.CLOSE_ALL_TEXT,
                              ActionFactory.createCloseAllActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.CLOSE_OTHERS_TEXT,
                              ActionFactory.createCloseOthersActionListener()));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.EXIT_TEXT,
                              ActionFactory.createExitActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)));

      return MENU;
   } // END createFileMenu

   /**
    * createTabPaneContextMenu method<br/>
    * This menu is created and shown when the user right-clicks on a tab.<br/>
    * @return JPopupMenu The pop-up menu.<br/>
    * @see ActionFactory#createFindActionListener()
    * @see ActionFactory#createReplaceActionListener()
    * @see ActionFactory#createSaveActionListener()
    * @see ActionFactory#createSaveAsActionListener()
    * @see ActionFactory#createSaveAsTemplateActionListener()
    * @see ActionFactory#createTranslateTemplateActionListener()
    * @see ActionFactory#createCloseActionListener()
    * @see ActionFactory#createCloseAllActionListener()
    * @see ActionFactory#createCloseOthersActionListener()
    */
   public static JPopupMenu createTabPaneContextMenu() {
      final JPopupMenu CONTEXT_MENU = new JPopupMenu();

      CONTEXT_MENU.add(createSeparator());
      CONTEXT_MENU.add(createMenuItem(Constants.FIND_TEXT,
                                      ActionFactory.createFindActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.REPLACE_TEXT,
                                      ActionFactory.createReplaceActionListener()));
      CONTEXT_MENU.add(createSeparator());
      CONTEXT_MENU.add(createMenuItem(Constants.SAVE_TEXT,
                                      ActionFactory.createSaveActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.SAVE_AS_TEXT,
                                      ActionFactory.createSaveAsActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.SAVE_AS_TEMPLATE_TEXT,
                                      ActionFactory.createSaveAsTemplateActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.TRANSLATE_TEMPLATE_TEXT,
                                      ActionFactory.createTranslateTemplateActionListener()));
      CONTEXT_MENU.add(createSeparator());
      CONTEXT_MENU.add(createMenuItem(Constants.CLOSE_TEXT,
                                      ActionFactory.createCloseActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.CLOSE_ALL_TEXT,
                                      ActionFactory.createCloseAllActionListener()));
      CONTEXT_MENU.add(createMenuItem(Constants.CLOSE_OTHERS_TEXT,
                                      ActionFactory.createCloseOthersActionListener()));

      return CONTEXT_MENU;
   } // END createTabPaneContextMenu

   /**
    * createEditMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see ActionFactory#createFindActionListener()
    * @see ActionFactory#createReplaceActionListener()
    * @see ActionFactory#createViewEnvironmentPropertiesActionListener()
    * @see ActionFactory#createGetUniqueNumActionListener()
    * @see ActionFactory#createDicePanelActionListener()
    * @see ActionFactory#createDiceModPanelActionListener()
    * @see ActionFactory#createSearchActionListener()
    * @see ActionFactory#createCodecActionListener()
    * @see ActionFactory#createJavaDocGenActionListener()
    * @see ActionFactory#createCalculatorActionListener()
    * @see ActionFactory#createCharacterGenActionListener()
    */
   public static JMenu createEditMenu() {
      final JMenu MENU = new JMenu(Constants.EDIT_TEXT);

      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.FIND_TEXT,
                              ActionFactory.createFindActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.REPLACE_TEXT,
                              ActionFactory.createReplaceActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.ENVIRONMENT_PROPERTIES_TEXT,
                              ActionFactory.createViewEnvironmentPropertiesActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createMenuItem(Constants.GET_UNIQUE_NUM_TEXT,
                              ActionFactory.createGetUniqueNumActionListener(),
                              KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK)));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.DICE_PANEL_TEXT,
                              ActionFactory.createDicePanelActionListener()));
      MENU.add(createMenuItem(Constants.DICE_MOD_PANEL_TEXT,
                              ActionFactory.createDiceModPanelActionListener()));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.SEARCH_TEXT,
                              ActionFactory.createSearchActionListener()));
      MENU.add(createMenuItem(Constants.ENCODE_DECODE_TEXT,
                              ActionFactory.createCodecActionListener()));
      MENU.add(createMenuItem(Constants.GEN_JAVA_DOC_TEXT,
                              ActionFactory.createJavaDocGenActionListener()));
      MENU.add(createMenuItem(Constants.CALCULATOR_TEXT,
                              ActionFactory.createCalculatorActionListener()));
      MENU.add(createSeparator());
      MENU.add(createMenuItem(Constants.CHARACTER_GEN_TEXT,
                              ActionFactory.createCharacterGenActionListener()));

      return MENU;
   } // END createEditMenu

   /**
    * createHtmlMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean)
    */
   public static JMenu createHtmlMenu() {
      final JMenu MENU = new JMenu(Constants.HTML_TEXT);

      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_HTML_TEMPLATE_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_HTML_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_HEAD_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_TITLE_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_STYLE_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_SCRIPT_TAGS_TEXT, false));
      MENU.add(createSeparator());
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_BODY_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_FORM_TAGS_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_INPUT_TAG_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.HTML_TEXT, Constants.GEN_IMG_TAG_TEXT, false));

      return MENU;
   } // END createHtmlMenu

   /**
    * createJavaMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean)
    */
   public static JMenu createJavaMenu() {
      final JMenu MENU = new JMenu(Constants.JAVA_TEXT);

      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_CLASS_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_FRAME_CLASS_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_FACTORY_CLASS_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_ENUM_TEXT, true));
      MENU.add(createSeparator());
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_MAIN_METHOD_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_METHOD_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_TRY_CATCH_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_TRY_CATCH_FINALLY_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_FILE_INPUT_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_FILE_OUTPUT_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_TEXT, Constants.GEN_ACTION_LISTENER_TEXT, false));

      return MENU;
   } // END createJavaMenu

   /**
    * createSqlMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean)
    */
   public static JMenu createSqlMenu() {
      final JMenu MENU = new JMenu(Constants.SQL_TEXT);

      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_SELECT_FROM_WHERE_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_INSERT_INTO_VALUES_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_UPDATE_SET_WHERE_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_DELETE_FROM_WHERE_TEXT, false));
      MENU.add(createSeparator());
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_ADD_COLUMN_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_DROP_COLUMN_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_ALTER_COLUMN_TEXT, false));
      MENU.add(createSeparator());
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_CURSOR_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_JOIN_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.SQL_TEXT, Constants.GEN_DROP_TABLE_OR_VIEW_TEXT, false));

      return MENU;
   } // END createSqlMenu

   /**
    * createJavaFXMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean)
    */
   public static JMenu createJavaFXMenu() {
      final JMenu MENU = new JMenu(Constants.JAVA_FX_TEXT);

      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_FX_TEXT, Constants.GEN_JAVA_FX_APPLICATION_CLASS_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_FX_TEXT, Constants.GEN_JAVA_FX_SCENE_CLASS_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.JAVA_FX_TEXT, Constants.GEN_JAVA_FX_EVENT_HANDLER_TEXT, false));

      return MENU;
   } // END createJavaFXMenu

   /**
    * createPythonMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean)
    */
   public static JMenu createPythonMenu() {
      final JMenu MENU = new JMenu(Constants.PYTHON_TEXT);

      MENU.add(createTextGenFromTemplateMenuItem(Constants.PYTHON_TEXT, Constants.GEN_PYTHON_MAIN_SCRIPT_TEXT, true));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.PYTHON_TEXT, Constants.GEN_PYTHON_TRY_EXCEPT_TEXT, false));
      MENU.add(createTextGenFromTemplateMenuItem(Constants.PYTHON_TEXT, Constants.GEN_PYTHON_TRY_EXCEPT_FINALLY_TEXT, false));

      return MENU;
   } // END createPythonMenu

   /**
    * createCustomMenu method<br/>
    * @return JMenu The menu.<br/>
    * @see #createTextGenFromTemplateMenuItem(JMenu, File)
    */
   public static JMenu createCustomMenu() {
      final JMenu MENU = new JMenu(Constants.CUSTOM_TEXT);

      for(final File FILE : Util.getDCEditCustomTemplates()) {
         MENU.add(createTextGenFromTemplateMenuItem(MENU, FILE));
      } // END loop

      return MENU;
   } // END createCustomMenu

   /**
    * createCharacterGenFileMenu method<br/>
    * @param DIALOG A dialog reference that gets passed to the close operation.<br/>It's a confirmation dialog.<br/>
    * @return JMenu The menu.<br/>
    * @see #createMenuItem(String, ActionListener)
    */
   public static JMenu createCharacterGenFileMenu(final JDialog DIALOG) {
      final JMenu MENU = new JMenu(Constants.FILE_TEXT);

      MENU.add(createMenuItem(Constants.SAVE_TEXT, ActionFactory.createCharacterGenSaveActionListener()));
      MENU.add(createMenuItem(Constants.LOAD_TEXT, ActionFactory.createCharacterGenLoadActionListener()));
      MENU.add(createMenuItem(Constants.CLOSE_TEXT, ActionFactory.createCloseDialogActionListener(DIALOG)));

      return MENU;
   } // END createCharacterGenFileMenu

   /**
    * createSeparator method<br/>
    * @return JSeparator A horizontally-oriented separator object.<br/>
    */
   public static JSeparator createSeparator() {
      return new JSeparator(JSeparator.HORIZONTAL);
   } // END createSeparator

   /**
    * createMenuItem method<br/>
    * @param TEXT The text to be shown in the menu item.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see #createMenuItem(String, ActionListener, KeyStroke)
    */
   public static JMenuItem createMenuItem(final String TEXT) {
      return createMenuItem(TEXT, null, null);
   } // END createMenuItem

   /**
    * createMenuItem method<br/>
    * @param TEXT The text to be shown in the menu item.<br/>
    * @param ACTION The action listener to be invoked on click of the menu item.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see #createMenuItem(String, ActionListener, KeyStroke)
    */
   public static JMenuItem createMenuItem(final String TEXT,
                                          final ActionListener ACTION) {
      return createMenuItem(TEXT, ACTION, null);
   } // END createMenuItem

   /**
    * createMenuItem method<br/>
    * @param TEXT The text to be shown in the menu item.<br/>
    * @param ACCELERATOR The key stroke which will auto-execute this menu item.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see #createMenuItem(String, ActionListener, KeyStroke)
    */
   public static JMenuItem createMenuItem(final String TEXT,
                                          final KeyStroke ACCELERATOR) {
      return createMenuItem(TEXT, null, ACCELERATOR);
   } // END createMenuItem

   /**
    * createMenuItem method<br/>
    * @param TEXT The text to be shown in the menu item.<br/>
    * @param ACTION The action listener to be invoked on click of the menu item.<br/>
    * @param ACCELERATOR The key stroke which will auto-execute this menu item.<br/>
    * @return JMenuItem The menu item.<br/>
    */
   public static JMenuItem createMenuItem(final String TEXT,
                                          final ActionListener ACTION,
                                          final KeyStroke ACCELERATOR) {
      final JMenuItem MENU_ITEM = new JMenuItem(null != TEXT ? TEXT : "");
      if(null != ACTION) MENU_ITEM.addActionListener(ACTION);
      if(null != ACCELERATOR) MENU_ITEM.setAccelerator(ACCELERATOR);
      return MENU_ITEM;
   } // END createMenuItem

   //---------------------------
   // Specialized Menu Functions
   //---------------------------

   /**
    * createLookAndFeelMenu method<br/>
    * @param APP Reference to the DCEdit frame class.<br/>
    * @return JMenu The menu.<br/>
    * @see ActionFactory#createLookAndFeelActionListener(DCEdit, String)
    */
   public static JMenu createLookAndFeelMenu(final DCEdit APP) {
      final JMenu MENU = new JMenu(Constants.LOOK_AND_FEEL_TEXT);

      // Populate this menu with all the Substance look and feel themes.
      for(final String LF_NAME : Constants.LF_OPTIONS) {
         final JMenuItem LF_MENU_ITEM = new JMenuItem(LF_NAME);
         LF_MENU_ITEM.addActionListener(ActionFactory.createLookAndFeelActionListener(APP, LF_NAME.replace(" ", "")));
         MENU.add(LF_MENU_ITEM);
      } // END loop

      return MENU;
   } // END createLookAndFeelMenu

   /**
    * createTextGenFromTemplateMenuItem method<br/>
    * @param MENU_TEXT Used to lookup a template file from the parent menu name.<br/>
    * @param MENU_ITEM_TEXT Used to lookup a template file from a menu item name.<br/>
    * @param OPEN_IN_NEW_TAB If true, will generate text in a brand new tab; otherwise will generate text wherever the cursor is in the current tab.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see #createTextGenFromTemplateMenuItem(String, String, boolean, KeyStroke)
    */
   public static JMenuItem createTextGenFromTemplateMenuItem(final String MENU_TEXT,
                                                             final String MENU_ITEM_TEXT,
                                                             final boolean OPEN_IN_NEW_TAB) {
      return createTextGenFromTemplateMenuItem(MENU_TEXT, MENU_ITEM_TEXT, OPEN_IN_NEW_TAB, null);
   } // END createTextGenFromTemplateMenuItem

   /**
    * createTextGenFromTemplateMenuItem method<br/>
    * @param MENU_TEXT Used to lookup a template file from the parent menu name.<br/>
    * @param MENU_ITEM_TEXT Used to lookup a template file from a menu item name.<br/>
    * @param OPEN_IN_NEW_TAB If true, will generate text in a brand new tab; otherwise will generate text wherever the cursor is in the current tab.<br/>
    * @param ACCELERATOR The key stroke which will auto-execute this menu item.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see ActionFactory#createTextGenFromInternalTemplateActionListener(String, boolean)
    */
   public static JMenuItem createTextGenFromTemplateMenuItem(final String MENU_TEXT,
                                                             final String MENU_ITEM_TEXT,
                                                             final boolean OPEN_IN_NEW_TAB,
                                                             final KeyStroke ACCELERATOR) {
      final JMenuItem MENU_ITEM = new JMenuItem(MENU_ITEM_TEXT);

      final String TEMPLATE_PATH = Constants.TEMPLATES_PATH +
                                   "/" +
                                   MENU_TEXT.toLowerCase() +
                                   "/" +
                                   MENU_ITEM_TEXT.replaceAll("\\W", "") +
                                   Constants.TEMPLATE_SUFFIX;

      MENU_ITEM.addActionListener(ActionFactory.createTextGenFromInternalTemplateActionListener(TEMPLATE_PATH, OPEN_IN_NEW_TAB));

      if(null != ACCELERATOR) MENU_ITEM.setAccelerator(ACCELERATOR);

      return MENU_ITEM;
   } // END createTextGenFromTemplateMenuItem

   /**
    * createTextGenFromTemplateMenuItem method<br/>
    * @param MENU The parent menu of the menu item.<br/>
    * @param FILE The template file reference.<br/>
    * @return JMenuItem The menu item.<br/>
    * @see ActionFactory#createTextGenFromExternalTemplateActionListener(JMenu, JMenuItem, String, String)
    */
   public static JMenuItem createTextGenFromTemplateMenuItem(final JMenu MENU, final File FILE) {
      final JMenuItem MENU_ITEM = new JMenuItem(FilenameUtils.getBaseName(FILE.getAbsolutePath()));

      MENU_ITEM.addActionListener(ActionFactory.createTextGenFromExternalTemplateActionListener(MENU, MENU_ITEM, MENU_ITEM.getText(), FILE.getAbsolutePath()));

      return MENU_ITEM;
   } // END createTextGenFromTemplateMenuItem

   /**
    * createCharacterGenDialogMenuBar method<br/>
    * @param DIALOG A reference to the confirmation dialog.<br/>
    * @return JMenuBar The menu bar for the character generation dialog.<br/>
    * @see #createCharacterGenFileMenu(JDialog)
    */
   public static JMenuBar createCharacterGenDialogMenuBar(final JDialog DIALOG) {
      final JMenuBar MENU_BAR = new JMenuBar();

      MENU_BAR.add(createCharacterGenFileMenu(DIALOG));

      return MENU_BAR;
   } // END createCharacterGenDialogMenuBar
} // END class MenuFactory